package com.mikey.springcloud.controller;

import com.mikey.springcloud.pojo.Category;
import com.mikey.springcloud.service.CategoryService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author :Mikey
 * @description :
 * @create :2022-08-29 19:08:00
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/list")
    @HystrixCommand(fallbackMethod = "selectOneHystrix")
    public List<Category> selectOne() {
            throw new RuntimeException("出错了");
    }
    public List<Category> selectOneHystrix() {
        Category category = new Category();
        category.setName("Hystrix");
        List<Category>categories =new ArrayList<Category>();
        categories.add(category);
        return categories;
    }



}